#include "StdAfx.h"
#include "HttpException.h"

namespace HttpProtocol
{

CHttpException::CHttpException(DWORD dwError)
: errCode(dwError)
{
}

CHttpException::~CHttpException(void)
{
}

LPCWSTR CHttpException::What()
{
	LPVOID lpMsgBuf;
	DWORD cbSize;
	wstring _Str;

	cbSize = FormatMessage(
		FORMAT_MESSAGE_ALLOCATE_BUFFER | 
		FORMAT_MESSAGE_FROM_SYSTEM,
		NULL,
		errCode,
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
		(LPTSTR) &lpMsgBuf,
		0,
		NULL
		);

	if (cbSize == 0)
	{
		LocalFree(lpMsgBuf);
		return L"Unknown Error!";
	}

	_Str = (wstring)(LPCWSTR)(lpMsgBuf);
	LocalFree(lpMsgBuf);

	return _Str.c_str();
}

DWORD CHttpException::GetErrorCode(void)
{
	return errCode;
}

}